//
//  WXAlertVC.m
//  ImGuider
//
//  Created by 李陆涛 on 2017/10/26.
//  Copyright © 2017年 AudioCtrip. All rights reserved.
//

#import "WXAlertVC.h"
#import <Photos/Photos.h>

@interface WXAlertVC ()
@property (weak, nonatomic) IBOutlet UILabel *titleLabel;
@property (weak, nonatomic) IBOutlet UIImageView *imageView;
@property (weak, nonatomic) IBOutlet UILabel *describeLabel;
@property (weak, nonatomic) IBOutlet UIButton *saveBtn;
@property (weak, nonatomic) IBOutlet UIView *alertView;

@end

@implementation WXAlertVC

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.view.backgroundColor = [UIColor colorWithWhite:0 alpha:0.6];
}

- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
    
    UITouch *touch = [touches anyObject];
    if (touch.view != self.alertView) {
        
        [self dismissViewControllerAnimated:YES completion:nil];
    }
    
}

- (void)showWithVC:(UIViewController *)vc {
    
    self.modalPresentationStyle = UIModalPresentationOverCurrentContext|UIModalPresentationFullScreen;
    [vc presentViewController:self animated:YES completion:nil];
}


- (IBAction)saveAction:(id)sender {
    
    UIImage *image = [UIImage imageNamed:@"公众号"];
    
    if (!image) {
        
        [IGUtils showToast:MYLocalizedString(@"PUBLIC_SYSTEM_ERROR", nil)];
        return;
    }
    
    [PHPhotoLibrary requestAuthorization:^(PHAuthorizationStatus status) {

        
        if (status == PHAuthorizationStatusAuthorized) {
            [[PHPhotoLibrary sharedPhotoLibrary] performChanges:^{
                
                
                [PHAssetChangeRequest creationRequestForAssetFromImage:image];
                
            } completionHandler:^(BOOL success, NSError * _Nullable error) {
                
                dispatch_async(dispatch_get_main_queue(), ^{
                    
                    if (success) {
                        [IGUtils showToast:MYLocalizedString(@"PAYORDER_SAVEPHOTO", nil)];
                        [self dismissViewControllerAnimated:YES completion:nil];
                        
                    }
                });
                
            }];
        }
    }];
}


@end

